<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of Melange_Framework
 *
 * PHP-MVC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MVC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MVC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @package mvc
 *
 */

/**
 *
 */
require_once 'mvc/view/helper/zend/FormSelect.php';

/**
 * PHP_MVC_View_Form_Helper_FormWeeks class
 *
 * @category    Melange Framework
 * @package     mvc
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class PHP_MVC_View_Form_Helper_FormWeeks extends Zend_View_Helper_FormSelect {

    private function getWeeks($year) {

        $weeks = array(""=>"--");
        for($i=1; $i<=52; $i++) {
            $weeks[$i] = ($i < 10 ? "0" : "").$i." (".$this->pageContext->weekToDate($i, $year, "d M Y").")";
        }

//        for($i=1; $i<=3; $i++) {
//            $weeks[$i] = ($i < 10 ? "0" : "").$i." (".$this->pageContext->weekToDate($i, $year, "d M Y").")";
//        }

        return $weeks;
    }
    
    public function formWeeks($name, $value = null, $attribs = null, $year)
    {
        // Override the class if error (Made global in ActionController) exists for this field.
        $actionErrors = $this->pageContext->request->getAttribute(MVC::ERROR_KEY);
        if(!is_null($actionErrors) && !$actionErrors->isEmpty() && !is_null($actionErrors->get($name))) {
            $attribs["class"] = "error";
        }

        return parent::formSelect($name, $value, $attribs, self::getWeeks($year));
    }

    
}
?>